using System.Collections.ObjectModel;
using Microsoft.Practices.CompositeWeb.Interfaces;
using Microsoft.Practices.CompositeWeb.Services;
using PageFlowQuickstart.Modules.Customers.Tests.Mocks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Practices.CompositeWeb;
using Microsoft.Practices.ObjectBuilder;
using Microsoft.Practices.CompositeWeb.ObjectBuilder;

namespace PageFlowQuickstart.Modules.Customers.Tests
{
    [TestClass]
    public class CustomersModuleInitializerFixture
    {
        [TestMethod]
        public void CustomersGetsRegisteredOnSiteMap()
        {
            TestableModuleInitializer moduleInitializer = new TestableModuleInitializer();
            SiteMapBuilderService siteMapBuilder = new SiteMapBuilderService();

            moduleInitializer.RegisterSiteMapInformation(siteMapBuilder);

            SiteMapNodeInfo node = siteMapBuilder.GetChildren(siteMapBuilder.RootNode.Key)[0];
            Assert.AreEqual("Customers", node.Key);
        }
    }

    namespace Mocks
    {
        class TestableModuleInitializer : CustomersModuleInitializer
        {
            public new void RegisterSiteMapInformation(ISiteMapBuilderService siteMapBuilderService)
            {
                base.RegisterSiteMapInformation(siteMapBuilderService);
            }
        }

        class MockRootCompositionContainer : CompositionContainer
        {
            public MockRootCompositionContainer()
            {
                InitializeRootContainer(CreateBuilder());
            }

            private WCSFBuilder CreateBuilder()
            {
                WCSFBuilder builder = new WCSFBuilder();
                builder.Policies.SetDefault<ISingletonPolicy>(new SingletonPolicy(true));
                return builder;
            }
        }
    }
}
